package br.com.aquinoevasconcelos.servlets.orcamento;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.aquinoevasconcelos.fachada.Fachada;
import br.com.aquinoevasconcelos.modelos.Orcamento;

/**
 * Servlet implementation class RemoverOrcamento
 */
@WebServlet("/RemoverOrcamento")
public class RemoverOrcamento extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public RemoverOrcamento() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fachada fachada = Fachada.getInstancia();
		Orcamento orcamento = new Orcamento();

		String id = request.getParameter("id");
		orcamento.setId(Long.parseLong(id));

		orcamento.setId(Long.parseLong(request.getParameter("id")));

		try {

			fachada.removerOrcamento(orcamento);

			RequestDispatcher rd = request
					.getRequestDispatcher("ListaOrcamento");
			rd.forward(request, response);

		} catch (Exception e) {
			e.printStackTrace();
			RequestDispatcher rd = request.getRequestDispatcher("../erro.jsp");
			rd.forward(request, response);
		}
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
